package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(1) // 设置优先级
@Component
@Aspect // 切面
public class SysTimeAspect {
    @Pointcut("bean(sysUserServiceImpl)") // 切入点 bean表达式
    public void doTime(){}

    @Before("doTime()")// advice 通知
    public void before(){
        System.out.println("SysTimeAspect.before");
    }

    @AfterReturning("doTime()")
    public void afterReturning() {
        System.out.println("SysTimeAspect.AfterReturning");
    }

    @AfterThrowing("doTime()")
    public void afterThrowing() {
        System.out.println("SysTimeAspect.AfterThrowing");
    }

    @After("doTime()")
    public void after() {
        System.out.println("SysTimeAspect.after");
    }

    @Around("doTime()")
    public Object around(ProceedingJoinPoint pj) throws Throwable {
        try {
            System.out.println("SysTimeAspect.around...before");
            Object result = pj.proceed();
            System.out.println("SysTimeAspect.around...after");
            return result;
        } catch(Throwable e) {
            e.printStackTrace();
            throw e;
        }
    }
}
